//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//   PACKAGE : dcf
//   FILE    : Envelope.java
//   CLASS   : Envelope
//   DATE    : 2006-04-01
//
//   DESCRIPTION
//   The Envelope class is the container in which messages are delivered.
//
//   It consists of a destination address and a message.
//
//
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//   Copyright (c) 2006 by Hal Smith
//
//   Permission is hereby granted, free of charge, to any person obtaining a copy of this source code 
//   (the "Code")to deal with the Code without restriction, including without limitation the rights to use, copy,
//   modify, merge, publish and distribute the Code, and to permit persons to whom the Code is furnished to do 
//   so, subject to the following conditions:
//
//   The above copyright notice and this permission notice shall be included in all copies or substantial 
//   portions of the Software.
//   
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//   VERSION HISTORY
//
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

package dcf;

import java.io.*;


class Envelope implements Serializable {

    // The host id and port number of where the message is to be sent.
    //
    private String  destinationHost;
    private int     destinationPort;


    // This is the message being sent.
    //
    private Message message;


    // Constructor.
    //
    // This operation initializes the envelope by setting the destination address to that provided and
    // inserting the specified message.
    //
    public Envelope(Endpoint initDestination, Message initMessage) throws InitializationException {

        // If either of the supplied parameters are null, log an error and throw an InitializationException.
        // Otherwise, save off the necessary data locally.
        //
        if (initDestination == null ||
            initMessage     == null ) {

                System.out.println("Envelope.Envelope(initDestination, initMessage):");
                System.out.println("   Both parameters must be non-null.");
                System.out.println("   Destination parameter null? " + (initDestination == null));
                System.out.println("   Message parameter null?     " + (initMessage     ==null));

                throw new InitializationException();

            } else {

                destinationHost = initDestination.getHost();
                destinationPort = initDestination.getPort();
                message         = initMessage;

            }

    } // constructor


    // This operation returns the host identifier of where the envelope is being sent. There are no exceptions
    // thrown by this operation.
    //
    public String getHost() {

        return destinationHost;

    } // getHost()


    // This operation returns the port number of where the envelope is being sent. There are no exceptions
    // thrown by this operation.
    //
    public int getPort() {

        return destinationPort;

    } // getPort()


    // This operation returns the message contained in the envelope. There are no exceptions thrown by this
    // operation.
    //
    public Message getMessage() {

        return message;

    } //getMessage()


} // Envelope